#include "test.h"
#include "misc_utils.h"

void test_string(void)
{
    STRING_T* str = NULL;
    STRING_T** ary = NULL;
    str = string_new("hello, world");
    EXPECT(string_equal(str->data, "hello, world"));
    string_destroy(str);

    str = string_cat("hello, ", "world");
    EXPECT(string_equal(str->data, "hello, world"));
    string_destroy(str);

    str = string_printf("hello, %s", "world");
    EXPECT(string_equal(str->data, "hello, world"));
    string_destroy(str);

    ary = string_split("hello, world", ", ");
    EXPECT(ary[0] != NULL);
    EXPECT(ary[1] != NULL);
    EXPECT(ary[2] == NULL);
    EXPECT(string_equal(ary[0]->data, "hello"));
    EXPECT(string_equal(ary[1]->data, "world"));
    string_destroy(ary[0]);
    string_destroy(ary[1]);
    free(ary);

    str = string_substr("hello, world", 0, 5);
    EXPECT(string_equal(str->data, "hello"));
    string_destroy(str);

    str = string_substr("hello, world", 7, 5);
    EXPECT(string_equal(str->data, "world"));
    string_destroy(str);

    str = string_trim("   hello    \n");
    EXPECT(string_equal(str->data, "hello"));
    string_destroy(str);
}
